// app.js
module.exports = app => {
  app.beforeStart(async () => {
    // 从配置中心获取 MySQL 配置 { host, port, password, ... }
    const mysqlConfig = await app.model.TDataSource.findAll({
      where: {
        // id: 1,
      },
    });
    app.Sequelize.clients = {};
    for (let i = 0; i < mysqlConfig.length; i++) {
      const item = mysqlConfig[i];
      console.log('mysqlConfigmysqlConfig', item);
      // app.databases[item.name] = await app.mysql.createInstanceAsync(item);
      app.Sequelize.clients[item.id] = new app.Sequelize.Sequelize({
        dialect: item.dialect,
        host: item.host,
        port: item.port,
        username: item.username,
        password: item.password,
        database: item.database,
      });
      // debugger
    }

    // 动态创建 MySQL 实例
  });
};
